﻿@{
    ViewBag.Title = "系统功能配置";
}
<div class="container">
    <ol class="breadcrumb">
        <li><a href="/xt/index">系统配置</a></li>
        <li class="active">功能录入</li>
    </ol>

    <div class="panel panel-primary">
        <div class="panel-heading">职工信息</div>
        <div class="panel-body form-inline">

            <label>功能ID/功能名称：<input id="sch_keyword" type="text" style="width: 120px;" /></label>

            @Html.MyButton("btn_sch", "搜索")

            @Html.MyButton("btn_add", "新增", "primary")

            @Html.MyButton("btn_edit", "编辑", "danger")
        </div>

        <table id="maingrid"></table>
        <div class="panel-footer">
            <ul id="page1"></ul>
        </div>
    </div>
</div>

<div id="hid_add_form" class="hide formpanel">
    <form id="form1" class="form-horizontal" role="form">

        <div>
            @Html.Hidden("GN_ID")

            <label>
                功能名称: 
                <input name="GN_MC" class="notnull" /></label>

        </div>
        <div>
            <label>
                Controller:
                <input name="GN_CONTROLLER" class="notnull" />
            </label>
        </div>
        <div>
            <label>
                Action:
                <input name="GN_ACTION" id="GN_ACTION" class="notnull" /></label>
        </div>
        <div>
            <label>
                简写码:
                <input name="JXM" /></label>

        </div>
    </form>
</div>


@section script
{

    <script src="@Url.Content("~/Scripts/plugins/bootstrap-paginator.min.js")"></script>
    <script src="@Url.Content("~/Scripts/plugins/jquery.grid.js")"></script>

    <script type="text/javascript">
        $(function () {

            $("#btn_sch").click(function () {
                sch();
            });

            function resetForm() {
                $("#form1 :hidden").val("");
                $("#form1").get(0).reset();
            }

            $("#btn_add").click(function () {
                resetForm();
                var html = $("#hid_add_form").removeClass("hide");
                mainfn.dialog("添加功能", html, save, false);
            });

            $("#btn_edit").click(function () {
                var row = $("#maingrid").bootgrid("getGridSelRow");
                if (row) {
                    bindForm(row);
                }
            });

            function bindForm(row) {
                mainfn.loadForm($("#form1"), row);
                var html = $("#hid_add_form").removeClass("hide");
                mainfn.dialog("编辑功能", html, save, false);
            }

            function save() {

                if (mainfn.checkForm($("#form1"))) {
                    return false;
                }

                var s = $("#form1").serialize();
                var url = "/xt/fnadd";
                if ($("#GN_ID").val()) {
                    url = "/xt/fnedit";
                }
                $.post(url, s, function (msg) {
                    mainfn.msg(msg.msg);
                    if (msg.flag) {
                        sch();
                    }
                });

                $("#form1").get(0).reset();

                return true;
            }

            $("#sch_keyword").bind("keydown", function (evt) {
                var e = evt || widows.event;
                if (e.keyCode == "13") {
                    sch();
                }
            });

            function sch() {
                $("#maingrid").bootgrid("setGridParam", { sch_keyword: $("#sch_keyword").val() });
                $("#maingrid").bootgrid("reloadGrid", { page: 1 });
            }

            function init(parameters) {

                $("#maingrid").bootgrid({
                    url: '/xt/fnlist',
                    pager: "page1",
                    headers: ["功能ID", "功能名称", "CONTROLLER", "ACTION", "JXM"],
                    cols: [
                        { id: 'GN_ID' },
                        { id: 'GN_MC' },
                        { id: 'GN_CONTROLLER' },
                        { id: 'GN_ACTION' },
                        { id: 'JXM', hidden: true }],
                    ondbclick: function (e, id, row) {
                        bindForm(row);
                    }
                });

            }

            init();
        });
    </script>
}